# ---------------------------------------------------------------------------------------------------- #
# _BrownFarissMcMahon_R_code_README.txt
# ---------------------------------------------------------------------------------------------------- #

 Date: 2015-02-16

 Authors: Cameron S. Brown, Christopher J. Fariss, and R. Blake McMahon

 Title: Recouping after Coup-Proofing: Compromised Military Effectiveness and Strategic Substitution  
 Most recent version available at: http://ssrn.com/abstract=1991257

 Contact: 
   Blake McMahon: rblakemcmahon@gmail.com 
   Chris Fariss: cjf0006@gmail.com
   Cameron Brown: cameron.s.brown@gmail.com

 Copyright (c) 2015, under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
 For more information see: http://creativecommons.org/licenses/by-nc-sa/3.0/us/
 All rights reserved. 


# ---------------------------------------------------------------------------------------------------- #
# install R and necessary packages for analysis
# ---------------------------------------------------------------------------------------------------- #

open the .R file using any text or source code editor such as:
	TextEdit, emacs, Aquamacs, notepad++ , or Xpad

set the working directory to the folder containing the data files 

the set working directory command in R is setwd()
	type ?setwd for help documentation 

to set the path type into R: 

setwd("PATH_NAME")

where PATH_NAME is the path to the folder with the data

install packages if necessary:
	install.packages("MASS")
	install.packages("foreign")
	install.packages("reshape")
	install.packages("xtable")
	install.packages("rjags")

You should place the folders that contain this file and the additional folders it contains into the R working directory. 

The R working directory is available via the getwd() function in R.

The attached code makes use of the file structure. As long as the folders are in the R working directory the script will find these files and work properly. 

The last version of R and Mac OS-X are:

	R version 3.1.1 (2014-07-10) -- "Sock it to Me"
	Copyright (C) 2014 The R Foundation for Statistical Computing
	Platform: x86_64-apple-darwin10.8.0 (64-bit)

The rjags library will only install after the successful installation of JAGS, which can be downloaded here: http://mcmc-jags.sourceforge.net/


# ---------------------------------------------------------------------------------------------------- #
# file descriptions
# NOTE: panels created below correspond to 7 figures in the main manuscript and 13 
# figures in the appendix. This includes all figures presented in both documents. 
# ---------------------------------------------------------------------------------------------------- #


1. RECOUPING_DATA_FOR_PUBLICATION.dta, which is the main dataset.

2. iraq_rug_1986.dta, contains the distribution of Effective Number, ln, which is used to build the rug on the x-axis of Figures 1 and 2.

3. Article_Tables_2-4.do, which contains the code to replicate Tables 2, 3, and 4 from the article.

4. Appendix_Tables_10-13.do, which contains the code to replicate Tables 10, 11, 12, and 13 from the appendix (see the Appendix for more details).

5. Figure_1.txt, which is a text file that contains the STATA and R code to recreate Figure 1 from the article. 

6. Figure_2.txt, which is a text file that contains the STATA and R code to recreate Figure 2 from the article. 

7. recouping_negbin_Appendix_Rcode_SPEC01.bug, JAGS model file for specification 01 (see recouping_negbin_Appendix_Rcode.R)8. recouping_negbin_Appendix_Rcode_SPEC02.bug, JAGS model file for specification 02 (see recouping_negbin_Appendix_Rcode.R)9. recouping_negbin_Appendix_Rcode_SPEC03.bug, JAGS model file for specification 03 (see recouping_negbin_Appendix_Rcode.R)10. recouping_negbin_Appendix_Rcode_SPEC04.bug, JAGS model file for specification 04 (see recouping_negbin_Appendix_Rcode.R)11. recouping_negbin_Appendix_Rcode.R, R code to run Bayesian negative binomial model (see Appendix for more details)12. recouping_negbin_Time_Varying_Appendix_Rcode_SPEC01.bug, JAGS model file for specification 01 (see recouping_negbin_Time_Varying_Appendix_Rcode.R)13. recouping_negbin_Time_Varying_Appendix_Rcode_SPEC02.bug, JAGS model file for specification 02 (see recouping_negbin_Time_Varying_Appendix_Rcode.R)14. recouping_negbin_Time_Varying_Appendix_Rcode_SPEC03.bug, JAGS model file for specification 03 (see recouping_negbin_Time_Varying_Appendix_Rcode.R)15. recouping_negbin_Time_Varying_Appendix_Rcode_SPEC04.bug, JAGS model file for specification 04 (see recouping_negbin_Time_Varying_Appendix_Rcode.R)16. recouping_negbin_Time_Varying_Appendix_Rcode.R, R code to run alternative Bayesian negative binomial model (see Appendix for more details)

17. recouping_SEM_Appendix_Rcode.bug, R code to run Bayesian Structural Equation Models (see Appendix for more details)18. recouping_SEM_Appendix_Rcode.R, JAGS model file for recouping_SEM_Appendix_Rcode.bug


# ---------------------------------------------------------------------------------------------------- #
# end file
# ---------------------------------------------------------------------------------------------------- #
